﻿using System;
using System.Collections.Generic;
using UnityEngine;

public class Shoot
{

    #region Atributos
    
    private Sprite2D _spriteShoot;
    private Vector2 _direction;
    
    private const float Speed = 700f;

    public bool ImDead { get; set; }

    public Rect CollisionRect { get; private set; }

    #endregion 

    #region Construtor
    
    public Shoot(float rotation,  Vector2 direction, Vector2 position)
    {
       _spriteShoot = new Sprite2D("Images/Game Elements/Shoot", position);
       _spriteShoot.Rotacao = rotation;
       
        Vector2 center = new Vector2( _spriteShoot.Position.x + _spriteShoot.Largura / 2, _spriteShoot.Position.y + _spriteShoot.Altura / 2  );
        Vector2 mousePosition = new Vector2( Input.mousePosition.x, Screen.height - Input.mousePosition.y  );

        _direction = mousePosition - center;
        _direction = _direction.normalized;
       
    }
    
    #endregion 

    #region Update

    public void Update()
    {
        _spriteShoot.Position += _direction*Speed*Time.deltaTime;

        CollisionRect = new Rect(_spriteShoot.Position.x, _spriteShoot.Position.y, _spriteShoot.Largura, _spriteShoot.Altura);

        if ( !new Rect( 0, 0, Constantes.TELA_LARGURA, Constantes.TELA_ALTURA ).Contains(_spriteShoot.Position) )
        {
            ImDead = true;
        }
    }

    #endregion 

    #region Draw

    public void Draw()
    {
        _spriteShoot.Draw(new Vector2(_spriteShoot.Position.x,_spriteShoot.Position.y));
    }

    #endregion 


}
